﻿using Mario.DataFiles;
using Mario.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Mario
{
    public partial class MainWindow1 : Form
    {
        private SoundPlayer Player = new SoundPlayer();
        public MainWindow1()
        {
            InitializeComponent();
            DoubleBuffered = true;
            ScorePanel.Visible = false;
            SettingsPanel.Visible = false;
            Start.Parent = MainPanel;
            try
            {
                this.Player.Stream = (Resources.Resource1.MainMusic);
                this.Player.PlayLooping();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error playing sound");
            }
        }
        /// <summary>
        /// Exit from application
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Exit_Click(object sender, EventArgs e)
        {
            Close();
        }

        /// <summary>
        /// Start game method
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Start_Click(object sender, EventArgs e)
        {
            Hide();
            Player.Stop();
            PreviewWindow preview = new PreviewWindow();
            preview.Show();

           // GameWindow window = new GameWindow();
           // window.Show();
        }

        /// <summary>
        /// Settings button click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Settings_Click(object sender, EventArgs e)
        {
            MainPanel.Visible = false;
            SettingsPanel.Visible = true;
        }

        private void Score_Click(object sender, EventArgs e)
        {
            MainPanel.Visible = false;
            XMLAccess xmlAccess = new XMLAccess();
            ScorePanel.Visible = true;
            Dictionary<int, string> scoreDictionary = xmlAccess.GetDataFromXML();
            var list = scoreDictionary.Keys.ToList();
            scoreGrid.Rows.Clear();
            scoreGrid.Height = list.Count * 50;
            for (int i = 0; i < scoreDictionary.Count; i++)
            {
                scoreGrid.Rows.Add();
                scoreGrid.Rows[i].Cells[0].Value = i + 1;
                scoreGrid.Rows[i].Cells[2].Value = list[i];
                scoreGrid.Rows[i].Cells[1].Value = scoreDictionary[list[i]];
                scoreGrid.Rows[i].Height = 50;

            }
        }

        /// <summary>
        /// Back button click on score
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backButton_Click(object sender, EventArgs e)
        {
            MainPanel.Visible = true;
            ScorePanel.Visible = false;
        }

        //Appearence settings set - Start {
        private void backButton_MouseHover(object sender, EventArgs e)
        {
            backButton.FlatAppearance.BorderSize = 2;
        }

        private void backButton_MouseLeave(object sender, EventArgs e)
        {
            backButton.FlatAppearance.BorderSize = 0;
        }

        private void settingsBackButton_Click(object sender, EventArgs e)
        {
            MainPanel.Visible = true;
            SettingsPanel.Visible = false;
        }

        private void settingsBackButton_MouseHover(object sender, EventArgs e)
        {
            settingsBackButton.FlatAppearance.BorderSize = 2;
        }

        private void settingsBackButton_MouseLeave(object sender, EventArgs e)
        {
            settingsBackButton.FlatAppearance.BorderSize = 0;
        }

        private void Start_MouseHover(object sender, EventArgs e)
        {
            Button temp = (Button)sender;
            temp.FlatAppearance.BorderSize = 3;
        }

        private void Start_MouseLeave(object sender, EventArgs e)
        {
            Button temp = (Button)sender;
            temp.FlatAppearance.BorderSize = 0;
        }
        //Appearence buttons set } - End
    }
}
